package beans;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import communication.QVaccinecontrol;
import java.io.IOException;
import java.util.ArrayList;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import model.Vaccinecontrol;
import org.codehaus.jettison.json.JSONException;

/**
 *
 * @author Fernando
 */
@ManagedBean
@RequestScoped
public class Bean {

    /** Creates a new instance of Get */
    public Bean() {
    }

    public String vaccine() throws IOException, JSONException {

        QVaccinecontrol SV = new QVaccinecontrol(1);

        return SV.getJson();
    }

    public static void main(String[] args) throws IOException, JSONException {

        /*QVaccine SV = new QVaccine();
        
        ArrayList<Vaccine> All = SV.GetAll();
        
        for (Vaccine V : All){
        
        System.out.println(V.getVaccineName());        
        }*/

        //boolean R = QVaccine.Insert(3, "sarampo");

        //System.out.println(R);
        QVaccinecontrol QV = new QVaccinecontrol();

        //boolean R = QV.Update(1, "dengue");

        //System.out.println(R);
    }
    /*public String json() throws IOException {
    
    //return "CRAP";
    HttpClient httpclient = new DefaultHttpClient();
    
    String json = "";
    
    // Prepare a request object
    HttpGet httpget = new HttpGet("http://localhost:8000/web/vaccine");
    
    // Execute the request
    HttpResponse response = httpclient.execute(httpget);
    
    // Examine the response status
    System.out.println(response.getStatusLine());
    
    // Get hold of the response entity
    HttpEntity entity = response.getEntity();
    
    // If the response does not enclose an entity, there is no need
    // to worry about connection release
    if (entity != null) {
    InputStream instream = entity.getContent();
    try {
    
    BufferedReader reader = new BufferedReader(
    new InputStreamReader(instream));
    // do something useful with the response
    
    json = reader.readLine();
    } catch (IOException ex) {
    
    // In case of an IOException the connection will be released
    // back to the connection manager automatically
    throw ex;
    
    } catch (RuntimeException ex) {
    
    // In case of an unexpected exception you may want to abort
    // the HTTP request in order to shut down the underlying
    // connection and release it back to the connection manager.
    httpget.abort();
    throw ex;
    
    } finally {
    
    // Closing the input stream will trigger connection release
    instream.close();
    
    }
    // When HttpClient instance is no longer needed,
    // shut down the connection manager to ensure
    // immediate deallocation of all system resources
    httpclient.getConnectionManager().shutdown();
    }
    return json;
    }*/
}
